package com.mz.mattress.api.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mz.mattress.api.common.BaseEntity;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.util.StringTools;
import lombok.Data;

import java.math.BigDecimal;

/**
 * 商家
 */
@Data
@TableName("mz_merchant")
public class Merchant extends BaseEntity {

    // 0是平台
    private Integer id;

    //memberMerId  0是平台
    private Long memberId;

    //手机号
    @ColumnWidth(20)
    @ExcelProperty(value = "商家手机号", index = 2)
    private String mobile;

    //商家名
    @ColumnWidth(20)
    @ExcelProperty(value = "商家名", index = 3)
    private String name;

    //图片
    private String img;

    //等级
    private Integer grade;

    //公司所在地  填省市区名称  逗号分隔
    private String path;

    //公司所在地  填省市区编码 逗号分隔
    private String pathNo;

    //省
    @ColumnWidth(20)
    @ExcelProperty(value = "省", index = 0)
    private String province;

    //市
    @ColumnWidth(20)
    @ExcelProperty(value = "市", index = 1)
    private String city;

    //区
    private String district;

    //地址
    private String address;

    //经度
    private BigDecimal lon;

    //纬度
    private BigDecimal lat;

    //经维度转换的hash编码
    private String geoHash;

    //logo图片
    private String logo;

    //一级销售员id
    private Integer topSaleId;

    //当前销售员id
    private Integer saleId;

    //销售员手机号
    @ColumnWidth(20)
    @ExcelProperty(value = "服务商手机号", index = 6)
    private String saleMobile;

    //销售员名字
    @ColumnWidth(20)
    @ExcelProperty(value = "服务商名", index = 7)
    private String saleName;

    //投资商id
    private Integer investorId;

    //投资商手机号
    @ColumnWidth(20)
    @ExcelProperty(value = "投资商手机号", index = 8)
    private String investorMobile;

    //投资商名字
    @ColumnWidth(20)
    @ExcelProperty(value = "投资商名", index = 9)
    private String investorName;

    //    再确认下营业中和审核通过这两个状态的门店啊；
//    营业中是指已经绑定设备的，审核通过是指通过审核还未绑定设备的；
    //状态 0初始状态 1待审核 2审核不通过 3审核通过 4暂停营业 5营业中 6已禁用

    //状态 0初始状态 1待审核 2审核不通过 3审核通过 5营业中 6已禁用
    @ColumnWidth(20)
    @ExcelProperty(value = "状态", index = 4)
    private Integer status;

    //是否开通卡项功能 1是 0否
    private Integer card;

    //设备数
    @ColumnWidth(20)
    @ExcelProperty(value = "设备数", index = 5)
    private Integer deviceCount;

    //提交时间
    private String submitTime;

    //审核时间
    private String checkTime;

    //入驻时间
    private String enterTime;

    //总收益 分
//    private Integer totalBonus;

    //原因
    private String reason;

    //营业执照
    @TableField(exist = false)
    private String license;

    //门店图片 多张逗号分割
    @TableField(exist = false)
    private String shop;

    //身份证照片正面
    @TableField(exist = false)
    private String identFront;

    //身份证照片背面
    @TableField(exist = false)
    private String identBack;

    //视频
    @TableField(exist = false)
    private String video;

    //备注
    @TableField(exist = false)
    private String remark;

    //  最新的一条审核记录
    @TableField(exist = false)
    private MerchantCheckRecord merchantCheckRecord;

    //设备总数
    @TableField(exist = false)
    private Integer deviceTotal;

    //设备离线数
    @TableField(exist = false)
    private Integer deviceOff;

    public Result valid() {

        if (StringTools.isEmpty(this.name)) {
            return Result.fail();
        }
        if (StringTools.isEmpty(this.license)) {
            return Result.fail("请上传营业执照");
        }
        if (StringTools.isEmpty(this.identFront) || StringTools.isEmpty(this.identBack)) {
            return Result.fail("请上传身份证");
        }
        if (StringTools.isEmpty(this.mobile) || this.mobile.length() != 11) {
            return Result.fail("手机号错误");
        }

        return Result.ok();
    }

    public MerchantDetail getMerchantDetail() {
        MerchantDetail detail = new MerchantDetail();
        detail.setId(id);
        detail.setLicense(license);
        detail.setShop(shop);
        detail.setIdentFront(identFront);
        detail.setIdentBack(identBack);
        detail.setRemark(remark);
        detail.setVideo(video);
        return detail;
    }

}
